package com.sto.stoapp.db;

import com.sto.stoapp.log.ExceptionLog;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class StoSingInfoTable {

	/**
	 * 表名:STO_SIGN_INFO_TABLE
	 */
	public final String SIGN_INFO_TABLE_NAME = "table_sto_sign_info";
	
	/******************** 代号,值区域功能表的字段 *********************/
	/**
	 *  简称(代号)
	 */
	public final String SIGN_INFO_KEY = "shortKey";
	/**
	 *  名称
	 */
	public final String SIGN_INFO_VALUE = "nameValue";
	/**
	 *  是否用户添加
	 */
	public final String SIGN_INFO_IS_USER = "userDefind";	
	/**
	 *  是否用户添加
	 */
	public final String SIGN_INFO_UNDEFIND1 = "undefind1";
	
	String[][] TabInfo = new String[][]{
			{"yjqsz", "邮件签收章"},
			{"qtqs", "前台签收"},
			{"cq", "草签"},
			{"yw", "英文"},
			{"1", "本人"},
			{"2", "同事代签"},
			{"3", "朋友代签"}
		};
	
	
	/**
	 * 初始化签收信息(代号->值)
	 */
	public void InitData(SQLiteDatabase db){

		String select = "SELECT COUNT(*) FROM "+ SIGN_INFO_TABLE_NAME;
		
		Cursor cursor = db.rawQuery(select, new String[]{});
		int rows = 0;
		if(cursor != null){
			if (cursor.moveToFirst()) {
				rows = cursor.getInt(0);
			}
			cursor.close();

			if (rows == 0) {

				try {
					db.beginTransaction();

					for (int i = 0; i < TabInfo.length; i++) {
						
						String inset = "INSERT INTO " + SIGN_INFO_TABLE_NAME
								+ " VALUES('" + TabInfo[i][0] + "' , '" + TabInfo[i][1]
								+ "', '0' , '')";

						db.execSQL(inset);
					}

				} catch (Exception e) {
					e.printStackTrace();
					ExceptionLog.writeLog("InitData", e.getMessage());
				} finally {
					db.setTransactionSuccessful();
					db.endTransaction();
				}
			}
		}
	}
	
}
